package com.cares.entity.mng;

import java.util.ArrayList;
import java.util.List;

import com.cares.entity.base.Entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Orgnization extends Entity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9155920905199293144L;

	private String nameCn;

	private String nameEn;

	private Long upOrgId;	

	private String orgPath;

	private String orgCode;
	
	private String airCode;
	private String officeCode;

	private String orgType;
	
	private String orgState;

	private String refKey;

	private String upOrgCode;
	private String upNameCn;
	
	@JsonIgnore
	private Orgnization upOrgnization;

	

	private int orgSort = 1000;

	public String getNameCn() {
		return nameCn;
	}

	public void setNameCn(String nameCn) {
		this.nameCn = nameCn == null ? null : nameCn.trim();
	}

	public String getNameEn() {
		return nameEn;
	}

	public void setNameEn(String nameEn) {
		this.nameEn = nameEn == null ? null : nameEn.trim();
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode == null ? null : orgCode.trim();
	}

	public String getOrgType() {
		return orgType;
	}

	public void setOrgType(String orgType) {
		this.orgType = orgType == null ? null : orgType.trim();
	}

	public String getRefKey() {
		return refKey;
	}

	public void setRefKey(String refKey) {
		this.refKey = refKey == null ? null : refKey.trim();
	}

	public Long getUpOrgId() {
		return upOrgId;
	}

	public void setUpOrgId(Long upOrgId) {
		this.upOrgId = upOrgId;
	}

	public String getOrgPath() {
		return orgPath;
	}

	public void setOrgPath(String orgPath) {
		this.orgPath = orgPath;
	}

	public int getOrgSort() {
		return orgSort;
	}

	public void setOrgSort(int orgSort) {
		this.orgSort = orgSort;
	}

	public String getUpOrgCode() {
		if (null != upOrgnization)
			return upOrgnization.getOrgCode();
		return null;
	}

	public String getUpNameCn() {
		if (null != upOrgnization)
			return upOrgnization.getNameCn();
		return null;
	}

	public Orgnization getUpOrgnization() {
		return upOrgnization;
	}

	public void setUpOrgnization(Orgnization upOrgnization) {
		this.upOrgnization = upOrgnization;
	}

	public String getOrgState() {
		return orgState;
	}

	public void setOrgState(String orgState) {
		this.orgState = orgState;
	}
	
	public String getAirCode() {
		if(null==airCode) return null;
		return airCode.toUpperCase();
	}

	public void setAirCode(String airCode) {
		this.airCode = airCode;
	}

	public String getOfficeCode() {
		return officeCode;
	}

	public void setOfficeCode(String officeCode) {
		this.officeCode = officeCode;
	}
	
	/**
	 * 提供遍历所有parent org的方法
	 * @return
	 */
	public List<Long> getParentIds(){
		List<Long> idList=new ArrayList<Long>();
		if(this.getOrgPath().contains(">>")){
			String[] tem=this.getOrgPath().split(">>");
			for(int i=tem.length-1;i>=0;i--){//末尾会增加一个>>
				idList.add(Long.parseLong(tem[i]));
			}
		}else{
			idList.add(this.getId());//没有的时候表示自己是顶层
		}
		return idList;
		
	}

	/**
	 * 返回org所在公司的orgid
	 * @return
	 */
	public Long getTopOrgId(){
		if(this.getOrgPath().contains(">>")){
			String[] pathArray = this.getOrgPath().split(">>");
			if(pathArray.length>1){
				String tem=this.getOrgPath().split(">>")[1];
				if(tem.trim().length()>0){
					return Long.parseLong(tem);
				}
			}			
		}
		return this.getId();
	}

	@Override
	public String toString() {
		return "Orgnization [nameCn=" + nameCn + ", nameEn=" + nameEn
				+ ", upOrgId=" + upOrgId + ", orgPath=" + orgPath
				+ ", orgCode=" + orgCode + ", airCode=" + airCode
				+ ", officeCode=" + officeCode + ", orgType=" + orgType
				+ ", orgState=" + orgState + ", refKey=" + refKey
				+ ", upOrgCode=" + upOrgCode + ", upNameCn=" + upNameCn
				+ ", upOrgnization=" + upOrgnization + ", orgSort=" + orgSort
				+ ", id=" + id + "]";
	}

	
	
	 
}